package model;
import java.io.IOException;

import xl.XLException;

import expr.*;
import expr.*;

public class CellFactory {

	public Cell createCell(String string) {
		ExprParser parse = new ExprParser();
		ExprCell cell;
		if(string.isEmpty()){
			throw new XLException("No input");
		}else if(string.charAt(0)=='#') {
			return new CommentCell(string.substring(1,string.length()));
			} else {
				
				try{
					cell = new ExprCell(parse.build(string));
				}catch(Exception IOException){
					throw new XLException("Was \"" + string + "\" should be an expression or begin with \"#\"");
				}
				
				return cell;
			}
	}
}
